// sp_core.cpp : Defines the entry point for the console application.
//

#include <libspotify\api.h>
#include <string>
#include <stdint.h>
#include "base64.h"
#include <stdlib.h>
using namespace std;
const uint8_t g_appkey[] = {
	0x01, 0x0B, 0x8F, 0x5E, 0x69, 0xE3, 0x6C, 0x3E, 0x08, 0x04, 0x49, 0xCD, 0xF5, 0x65, 0x41, 0x24,
	0x53, 0xD1, 0x46, 0x93, 0x20, 0x82, 0xA0, 0x37, 0x01, 0x6D, 0x17, 0x99, 0x4D, 0x37, 0x31, 0x6F,
	0xBB, 0x85, 0x85, 0xFE, 0xE6, 0x7F, 0x4F, 0x88, 0x59, 0x27, 0xE3, 0x64, 0x2A, 0x0C, 0x28, 0xF6,
	0x95, 0xE7, 0xBC, 0x68, 0xEB, 0x14, 0x2C, 0x5F, 0xF7, 0x32, 0x7F, 0x3B, 0x8A, 0x17, 0xBF, 0xC8,
	0x84, 0xC4, 0xE7, 0x2B, 0x4B, 0x96, 0xB8, 0x75, 0xF0, 0x60, 0xA8, 0xC3, 0xED, 0x6D, 0x47, 0x82,
	0x87, 0xC3, 0x51, 0xD4, 0x76, 0xE5, 0xAA, 0xFA, 0x15, 0xED, 0xFB, 0x04, 0x12, 0x7F, 0x40, 0x35,
	0x10, 0x85, 0x70, 0xA5, 0xF8, 0x62, 0xC3, 0x95, 0x6B, 0x30, 0x5B, 0x3C, 0x0E, 0x27, 0x01, 0x75,
	0x25, 0xE3, 0xCE, 0xC8, 0xA1, 0x27, 0x0A, 0x46, 0x9B, 0x00, 0x9D, 0xFC, 0xEF, 0x23, 0x56, 0x3C,
	0x8D, 0x10, 0x39, 0x20, 0x00, 0xBE, 0xAF, 0x25, 0x8F, 0x4F, 0x25, 0xB9, 0x42, 0xD0, 0xD6, 0xFD,
	0x3A, 0x73, 0x77, 0x22, 0xB7, 0x07, 0x22, 0x6E, 0xE1, 0x84, 0x85, 0x1F, 0xED, 0x04, 0x71, 0x4F,
	0xF0, 0x6C, 0x32, 0x0E, 0xED, 0x7A, 0xEB, 0x8F, 0x7E, 0x61, 0x22, 0x75, 0xCC, 0xEB, 0xB1, 0xEF,
	0x6A, 0x22, 0x29, 0x95, 0x68, 0x16, 0x57, 0xE2, 0x9F, 0x51, 0xC3, 0xCE, 0x26, 0xA6, 0x1B, 0xC8,
	0xFC, 0x7F, 0xF1, 0xDC, 0xF8, 0x65, 0x2B, 0x21, 0x8C, 0xFA, 0x51, 0xD1, 0x80, 0xFF, 0xD9, 0x48,
	0x26, 0x35, 0x12, 0xDA, 0x0B, 0x07, 0xD6, 0x1B, 0x15, 0xE9, 0x38, 0x05, 0x16, 0xAF, 0x57, 0x2D,
	0xE0, 0x27, 0x8F, 0xFD, 0x20, 0x33, 0x10, 0x36, 0x06, 0x2D, 0x5A, 0x20, 0xD7, 0xC2, 0x2A, 0x8C,
	0x94, 0x29, 0xD2, 0xF2, 0xEC, 0x96, 0x7E, 0x95, 0xE5, 0xB8, 0xDA, 0x59, 0x4C, 0x9C, 0xE7, 0xE1,
	0xA2, 0x23, 0x9F, 0x07, 0x51, 0x3A, 0x0E, 0xC4, 0xEF, 0x5F, 0x0F, 0x27, 0xEC, 0xC9, 0xB9, 0x4C,
	0x75, 0xF8, 0xA8, 0x84, 0x0C, 0x88, 0x93, 0x26, 0xD5, 0xF3, 0xC6, 0xA7, 0xC5, 0xCE, 0x2D, 0x67,
	0xDA, 0x09, 0xE4, 0xD8, 0xC9, 0x26, 0x10, 0xBE, 0x6F, 0x18, 0x6E, 0x00, 0xD2, 0x8A, 0x32, 0x81,
	0xB3, 0x8B, 0x3A, 0x96, 0x65, 0xD1, 0xEF, 0x60, 0xD5, 0x87, 0x01, 0x96, 0x55, 0xAA, 0x60, 0x30,
	0xCD,
};
const size_t g_appkey_size = sizeof(g_appkey);
int _tmain(int argc, char** argv)
{
	// create session
	sp_session* session;
	sp_session_config config;
	config.api_version = SPOTIFY_API_VERSION;
	sp_session_callbacks callbacks;
	sp_error error;
    // The path of the directory to store the cache. This must be specified.
    // Please read the documentation on preferred values.
    config.cache_location = "tmp";

    // The path of the directory to store the settings. 
    // This must be specified.
    // Please read the documentation on preferred values.
    config.settings_location = "tmp";

    // The key of the application. They are generated by Spotify,
    // and are specific to each application using libspotify.
    config.application_key = g_appkey;
    config.application_key_size = g_appkey_size;

    // This identifies the application using some
    // free-text string [1, 255] characters.
    config.user_agent = "linspot";

    // Register the callbacks.
    config.callbacks = &callbacks;

    error = sp_session_create(&config, &session);
    if (SP_ERROR_OK != error) {
        fprintf(stderr, "failed to create session: %s\n",
                        sp_error_message(error));
        return 2;
    }
	// login
	sp_session_create(&config,&session);
	sp_session_login(session,argv[0],argv[1]);

	// get the link
	sp_link *current_link = sp_link_create_from_string(argv[3]);

   // decide what to do by the character argument
	if(argv[4] ==  "image")
	{
		char* sp_uri = argv[5]; // get the uri
		
		// create album
		sp_album *album = sp_link_as_album(current_link);
		while(!sp_album_is_loaded(album));
		const byte *cover = sp_album_cover(album);
	
		std::string output base64_encode( 

		// get image
	

	}
}

